package com.scqkxx.gamebox.activity.home.adapter;

import android.content.ContentValues;
import android.view.View;
import android.widget.ImageView;

import com.avos.avoscloud.AVObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.activities.utils.ActivityUtil;
import com.scqkxx.gamebox.activity.group.GroupDetailActivity;
import com.scqkxx.gamebox.activity.group.GroupEditActivity;
import com.scqkxx.gamebox.activity.group.GroupJoinActivity;
import com.scqkxx.gamebox.activity.group.GroupMembersActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zsx on 2018/8/9.
 */

public class HomeNewsAdapter extends BaseQuickAdapter<AVObject, BaseViewHolder> {

    private List<AVObject> list = new ArrayList<>();

    public HomeNewsAdapter(int layoutResId, List<AVObject> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AVObject item) {
        helper.setText(R.id.tv_group_name, item.getString("name"));
        helper.setText(R.id.tv_group_content, item.getString("desc"));

        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.icon_user_header_default)
                .error(R.mipmap.icon_user_header_default)
                .centerCrop()
                .circleCrop();
        Glide.with(mContext)
                .load(item.getString("avatar"))
                .apply(options)
                .into((ImageView) helper.convertView.findViewById(R.id.iv_group_img));

        helper.convertView.findViewById(R.id.bt_invite_group).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String groupId = item.getObjectId();
                ContentValues contentValues = new ContentValues();
                contentValues.put("groupId",groupId);
                ActivityUtil.switchTo(mContext,GroupMembersActivity.class,contentValues);
            }
        });
        helper.convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String groupId = item.getObjectId();
                ContentValues contentValues = new ContentValues();
                contentValues.put("groupId",groupId);
                ActivityUtil.switchTo(mContext,GroupDetailActivity.class,contentValues);
            }
        });
    }

}